﻿	<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery.validate.js"></script>
		<script type="text/javascript" src="js/messages_zh.js"></script>
		
		<script type="text/javascript">
			$(function(){

				//表单验证
				$("#a").validate({
					rules:{
						username:"required",
						password:{
							required:true,
							minlength:6
						}
					}
				});

			})
			
			// 注册按钮点击时，触发的事件
			function regist1911(){
				// 获取表单校验结果
				var ret1 = $("#a").valid();
				if(ret1 && uname){// uname是用户名是否可用状态
					// 当一切校验都成功了 发送如下ajax
					$.ajax({
						xxx:xxx,
						xxx:xxx,
						xxx:xxx,
					});
				}
			}
			//当输入完用户名后，异步校验是否重复
			function checkUname(){
				// 发起ajax，携带当前用户名，到服务器校验
				$.ajax({
					xx:xx,
					....
					success:function(ret){
						if(ret=="1"){//如果用户名不重复即可用，则将状态存于全局变量中：uname
							uname=true;
						}else{
							uname=false;
						}
					}
				});
			}
		</script>
		<title>注册</title>
	</head>
	<body>
		<form action="http://www.baidu.com" id="a">
			<input name="username" onblur="checkUname();"/>  <br>
			<input name="password"/>  <br>
			<input type="button" value="提交" onclick="regist1911();"/>
		</form>
	</body>
</html>